package com.longge;

import java.util.HashMap;
import java.util.Stack;

/**
 * @创建人 xinglongge
 * @创建时间 2021/9/22@
 * @描述
 */
public class ValidBrackets {

    public boolean isValid(String s) {

        HashMap<Character, Character> map = new HashMap<>();
        map.put('(', ')');
        map.put('{', '}');
        map.put('[', ']');
        Stack<Character> chars = new Stack<>();
        for (char c : s.toCharArray()) {
           if (map.containsKey(c)){
               chars.push(c);
           }else {
               if (chars.isEmpty()||map.get(chars.pop())!=c){
                   return false;
               }
           }
        }

        return chars.isEmpty();

    }

    public static void main(String[] args) {
        new ValidBrackets().isValid("()]]]");
    }

}
